package com.lee.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lee.aspect.Log;
import com.lee.base.BaseController;
import com.lee.base.Result;
import com.lee.constant.BusinessType;
import com.lee.page.TableSupport;
import com.lee.system.api.IOperLogService;
import com.lee.system.entity.OperLog;
import com.lee.utils.ExcelUtil;

import io.swagger.annotations.Api;

/**
 * 操作日志记录
 * 
 * @author LiPengFei
 *
 */
@Api("操作日志记录")
@Controller
@RequestMapping("/system/operlog")
public class OperlogController extends BaseController {
	private String prefix = "system/operlog";

	@Reference
	private IOperLogService operLogService;

	@RequiresPermissions("system:operlog:view")
	@GetMapping()
	public String operlog() {
		return prefix + "/operlog";
	}

	@RequiresPermissions("system:operlog:list")
	@PostMapping("/list")
	@ResponseBody
	public Result list(OperLog operLog) {
		return Result.ok().page(operLogService.selectOperLogList(operLog,TableSupport.getPageDomain()));
	}

	@Log(title = "操作日志", action = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public Result export(OperLog operLog) throws Exception {
		try {
			List<OperLog> list = operLogService.selectOperLogList(operLog);
			ExcelUtil<OperLog> util = new ExcelUtil<OperLog>(OperLog.class);
			return util.exportExcel(list, "operLog");
		} catch (Exception e) {
			return Result.error("导出Excel失败，请联系网站管理员！");
		}
	}

	@RequiresPermissions("system:operlog:remove")
	@PostMapping("/remove")
	@ResponseBody
	public Result remove(String ids) {
		if (operLogService.deleteOperLogByIds(ids) > 0) {
			return Result.ok();
		}
		return Result.error();

	}

	@RequiresPermissions("system:operlog:detail")
	@GetMapping("/detail/{operId}")
	public String detail(@PathVariable("operId") Long deptId, Model model) {
		OperLog operLog = operLogService.selectOperLogById(deptId);
		model.addAttribute("operLog", operLog);
		return prefix + "/detail";
	}
}
